package gui.catalogues.telephones.models;

import gui.catalogues.telephones.interfaces.TelephonesTableListener;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;


public class TelephonesTablePanel extends JPanel {
	
	/*
	 * Variable declaration
	 * */
	private JTable t;
//	private JPopupMenu pum;
//	private JMenuItem jmiDeleteRow;
	private int rowNum;
//	private PersonTableListener ptl;
	private TelephonesTableListener telephonesTableListener;
	private TelephonesTableModel tm;
	Dimension dim = getPreferredSize();
	
	public TelephonesTablePanel() {
		/*
		 * Variable initialization
		 * */
		initVariables();	
		
		/*
		 * initializing and assigning popUp variables 
		 * */
//		pum = new JPopupMenu();
//		jmiDeleteRow = new JMenuItem("Borrar renglón");
//		pum.add(jmiDeleteRow);

		manageLayout();
//		add(new JScrollPane(t));
		/*
		 * manage actionListeners
		 * */
		manageActionListeners();
	}
	
	public void initVariables() {
		tm = new TelephonesTableModel();
		t = new JTable(tm);
		
	}
	
	public void manageLayout() {
		
		t.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
		t.getColumnModel().getColumn(0).setMaxWidth(25);
		t.getColumnModel().getColumn(1).setMaxWidth(60);
//		t.getColumnModel().getColumn(2).setPreferredWidth(116);
		dim.height = 95;
		dim.width = 190;
		setPreferredSize(dim);
		setMinimumSize(dim);
		setLayout(new BorderLayout());
		
		add(new JScrollPane(t), BorderLayout.CENTER);
	}
	
	public void manageActionListeners() {
		/*
		 * ActionListener to manage the right mouse click over the table
		 * */
//		t.addMouseListener(new MouseAdapter() {
//			@Override
//			public void mousePressed(MouseEvent e) {
//				// if the mouse button is the right one...
//				if(e.getButton() == MouseEvent.BUTTON3) {
//					System.out.println("Pressed right click on the telephonesTable");
//					// get the row number over which the right click was pressed
////					rowNum = t.rowAtPoint(e.getPoint());
////					// to set the row, I get its selectionModel and set in It the
////					// selection interval (1 to N rows)
////					t.getSelectionModel().setSelectionInterval(rowNum, rowNum);
////					// parent source table, and XY coordinates
////					pum.show(t, e.getX(), e.getY());
//				}
//			}
//		});
		
//		jmiDeleteRow.addActionListener(new ActionListener() {
//			public void actionPerformed(ActionEvent e) {
//				// get selected row
//				rowNum = t.getSelectedRow();
//				
//				/*
//				 * Will pass a rowDeleted method for the Main class -MainFrame- to implement its own
//				 * kind of rowDeleted method.
//				 * */
//				if(ptl != null) {
//					ptl.rowDeleted(rowNum);
//					ptm.fireTableRowsDeleted(rowNum, rowNum);
//				}
//				
//				
//			}
//		});
	}
	
//	public void setTableData(List<Object> tableData) {
//		ptm.setPeopleList(tableData);
//	}
//	
//	public void refresh() {
//		ptm.fireTableDataChanged();
//	}
//	
//	public void setPersonTableListener(PersonTableListener ptl) {
//		this.ptl = ptl;
//	}
	
	public void setTelephonesTableListener(TelephonesTableListener telephonesTableListener) {
		this.telephonesTableListener = telephonesTableListener;
	}
	
}
